<template>
	<view>
		<uni-list class="chat-list">
			<uni-list-chat v-for="item in listData" :key="item.id" :title="item.nickname" :avatar="item.headImg"
				:note="item.lastMsg" :time="item.updateTime" :clickable="true" badge-positon="left"
				:badge-text="item.unreadCount?item.unreadCount:''" @click="goToDetail(item)"></uni-list-chat>
		</uni-list>
	</view>
</template>

<script>
	import {
		url,
		request,
		login
	} from '@/service/api.js'
	export default {
		data() {
			return {
				listData: []
			};
		},
		onShow() {
			this.init()
			request(url.getUnreadMsg, 'GET').then(res => {
				console.log('unread', res)
				if (res.data > 0) {
					// uni.showTabBarRedDot({
					// 	index: 3,
					// 	text:123
					// })
					uni.setTabBarBadge({
						index: 3,
						text: res.data.toString()
					})
				}else{
					uni.removeTabBarBadge({
						index:3
					})
				}
			})
		},
		methods: {
			init() {
				this.getList()
			},
			getList() {
				request(url.getConversationList, 'GET', {}).then(res => {
					console.log(res)
					if (res.status === 200) {
						this.listData = res.data
					} else {

					}
				})
			},
			goToDetail(item) {
				uni.navigateTo({
					url: '/pages/MessageDetail/MessageDetail?conversationId=' + item.id + '&nickname=' + item
						.nickname
				})
			}
		}
	}
</script>

<style lang="less">
	.chat-list {
		// margin-top: 10px;
	}
</style>
